﻿using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace PD.ShP.Lists.EventReceivers
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class ConfigEventReceiver : SPItemEventReceiver
    {
        /// <summary>
        /// Synchronous Before event that occurs when a new item is added to its containing object.
        /// </summary>
        /// <param name="properties">Properties for asynchronous list item adding event handler.</param>
        public override void ItemAdding(SPItemEventProperties properties)
        {
            properties.Cancel = true;
            properties.ErrorMessage = "Addition of items is not allowed for this list.";
            properties.Status = SPEventReceiverStatus.CancelWithError;
        }

        /// <summary>
        /// Synchronous Before event that occurs before an existing item is completely deleted.
        /// </summary>
        /// <param name="properties">Properties for asynchronous list item deleting event handler.</param>
        public override void ItemDeleting(SPItemEventProperties properties)
        {
            properties.Cancel = true;
            properties.ErrorMessage = "Deletion of items is not allowed for this list.";
            properties.Status = SPEventReceiverStatus.CancelWithError;
        }
    }
}
